package com.hongyuan.sellfitness.ui.person.view_mode;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;
import com.hongyuan.sellfitness.BR;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomViewModel;
import com.hongyuan.sellfitness.data.MyRepository;
import com.hongyuan.sellfitness.ui.person.beans.MyGroupBean;
import java.util.List;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class GroupRecordViewModel extends CustomViewModel<MyRepository> {

    public GroupRecordViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //给RecyclerView添加ObservableList
    public ObservableList<GroupRecordItemViewModel> observableList = new ObservableArrayList<>();

    //给RecyclerView添加ItemBinding
    public ItemBinding<GroupRecordItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_group_record);


    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);

        if(code == Constants.GET_MEMBER_SIGN_UP_COURSE_SUPER_LIST){
            List<MyGroupBean.ListBean> mList = ((MyGroupBean)dataBean).getList();
            //清除旧数据
            if(curPage == FIRST_PAGE){
                observableList.clear();
            }

            if(mList != null && mList.size() > 0){
                for(MyGroupBean.ListBean bean : mList){
                    GroupRecordItemViewModel itemViewModel = new GroupRecordItemViewModel(this,bean);
                    observableList.add(itemViewModel);
                }
            }

            if(observableList.size() > 0){
                if(mList == null || mList.size() == 0){
                    getUC().getFinishLoadMoreData().call();
                }
            }else{

            }
        }

    }


}
